from transitions import Machine

class StringExtractor:
    states = ['Normal', 'IN_STRING', 'Final']    # 正常状态和字符串状态

    def __init__(self):
        self.machine = Machine(model=self, states=StringExtractor.states, initial='Normal')

        self.current_string = ""  # 用于存储提取的字符串

        # 双引号和反斜杠，进入注释状态
        self.machine.add_transition('first_double_quote_and_fxg', 'Normal', 'IN_STRING', conditions='is_double_quote_and_fxg')
        self.machine.add_transition('second_double_quote_and_fxg', 'IN_STRING', 'Normal', conditions='is_double_quote_and_fxg')
        self.machine.add_transition('found_end_quote', 'IN_STRING', 'Final', conditions='end_quote')

    def is_double_quote_and_fxg(self, character):
        # 检查是否 不是 \" 这个字符
        return character != '\\\"'

    def end_quote(self, character):
        # 判断是不是为 "
        return character == '\"'

